<template>

	<view :class="'coupon-list coupon-list-'+btnType">
		<radio-group>
			<view v-for="(item, index) in list" :key="index" class="coupon-items row-between"
				@click="changOneSelect(index)">
				<radio :checked="active === index" class="coupon-radio" v-if="btnType === 2" />
				<view :class="'coupon-item row-between coupon-item'+btnType">
					<view class="item-left">
						<view class="price-wrap">¥<text class="price-num">{{item.couponAmount}}</text></view>
						<view>{{item.threshold === 0 ? '无使用门槛' :''}}</view>
					</view>
					<view class="item-right">
						<view class="coupon-name line1">{{item.couponName}}</view>
						<view>有效期：{{item.endTimeStr}}</view>
					</view>
				</view>
			</view>
		</radio-group>
		<u-button v-if="btnType === 2" class="coupon-btn" size="medium" type="warning" shape="circle"
			@click="onSubmit()">确认使用</u-button>
	</view>
</template>


<script>
	import {
		getCoupon
	} from '../../api/user';

	export default {
		data() {
			return {
				active: null,
			};
		},

		components: {},
		props: {
			list: {
				type: Array,
				default: () => []
			},
			btnType: {
				// 0 去使用  1已使用 2已过期 3领取
				type: Number
			}
		},
		onLoad() {
			// console.log('---list------', this.list)
		},
		watch: {
			list: {
				handler: function(val) {
					let arr = val.map(item => {
						return 0;
					});
					this.showTips = arr
				},
				immediate: true,
				deep: true
			}
		},
		computed: {
			getBtn() {
				var text = ''
				switch (this.btnType) {

					case 0:
						text = '去使用';
						break;
					case 1:
						text = '已使用';
						break;
					case 2:
						text = '已过期';
						break;
					case 3:
						text = '领取';
						break;
				}
				return text
			}
		},
		methods: {
			changOneSelect(index) {
				if (this.active === index) {
					this.active = null
				} else {
					this.active = index
				}
			},
			onSubmit() {
				this.$emit('getCouPon', this.active === null ? {} : this.list[this.active]);
			},

			/* onHandle(id) {
				this.id = id;
				const {
					btnType
				} = this;

				switch (btnType) {
					case 0:
						uni.switchTab({
							url: '/pages/index/index'
						});
						break;

					case 1:
						// text = '去使用';
						break;

					case 2:
						// text = '已使用';
						break;

					case 3:
						this.getCouponFun();
						break;
				}
			},

			onShowTips(index) {
				const {
					showTips
				} = this;

				this.showTips[index] = showTips[index] ? 0 : 1
				// 拷贝数组
				this.showTips = Object.assign([], this.showTips);
			},

			getCouponFun() {
				getCoupon(this.id).then(res => {
					if (res.code == 1) {
						this.$toast({
							title: res.msg
						})
						this.$emit('reflash');
					}
				});
			} */

		}
	};
</script>
<style lang="scss">
	/* components/coupon-list/coupon-list.wxss */
	.coupon-list {
		position: relative;
		padding: 20rpx 24rpx;
		font-family: PingFangSC-Semibold, PingFang SC;

		&-2 {
			padding-bottom: 150rpx;
		}

		.coupon-radio {
			padding: 40rpx 5px;
		}

		.coupon-item {
			flex: 1;
			padding: 0 10rpx;
			height: 220rpx;
			font-size: 20rpx;
			color: #8C8C8C;
			background: url('/static/images/coupon-card.png') no-repeat center/contain;

			&2 {
				height: 202rpx;
			}

			.item-left {
				flex: 0 0 36%;
				text-align: center;
				font-weight: 600;

				.price-wrap {
					color: #FF8E07;
					font-size: 32rpx;
					font-family: PingFangSC-Semibold, PingFang SC;
					font-weight: 600;
					color: #FF8E07;

					.price-num {
						font-size: 60rpx;
						font-family: PingFangSC-Semibold, PingFang SC;
						font-weight: 600;
						color: #FF8E07;
					}
				}
			}

			.item-right {
				flex: 1;
				padding-left: 60rpx;
				width: 200rpx;

				.coupon-name {
					margin-bottom: 6rpx;
					font-size: 32rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					color: #343434;
					font-weight: 500;

				}
			}

		}

		.coupon-btn {
			position: fixed;
			bottom: 60rpx;
			left: 50%;
			transform: translateX(-50%);

			>button {
				width: 550rpx;
			}
		}

		&-1 {

			.coupon-item {
				.item-left {
					color: #9B9B9B;

					.price-wrap, .price-wrap .price-num {
						color: #9B9B9B
					}
				}

				.item-right .coupon-name {
					color: #9B9B9B;
				}
			}
		}

		/* .coupon-item {
			position: relative;
			height: 200rpx;
			// background-image: url(../../static/images/coupon_bg.png);
			background-size: 100% 100%;

			&.gray {

				// background-image: url(../../static/images/coupon_bg_grey.png);
				.btn {
					&.plain {
						color: #CCCCCC;
					}
				}
			}

			.price {
				width: 200rpx;
			}

			.btn {
				line-height: 52rpx;
				height: 52rpx;
				position: absolute;
				right: 20rpx;
				bottom: 20rpx;
				width: 120rpx;
				text-align: center;
				padding: 0;
				text-align: center;
				box-sizing: border-box;

				&.plain {
					background-color: #fff;
					color: var(--primary-color);
					border: 1px solid currentColor;
				}
			}

			.receive {
				position: absolute;
				right: 30rpx;
				top: 0rpx;
				width: 99rpx;
				height: 77rpx;
			}
		}

		.icon {
			transition: all 0.4s;
		}

		.rotate {
			transform: rotateZ(-180deg);
		} */
	}
</style>
